﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;

namespace Demo_HHT_EARTH
{
    public partial class EMCheckInConfirm : UserControl
    {
        SQLiteConnection cn2 = new SQLiteConnection();
        DataSet droplist = new DataSet();
       String strconinsert,group = string.Empty;
        public EMCheckInConfirm()
        {
            InitializeComponent();
            FindGroupEm();
            label6.Text = Demo_HHT_EARTH.DataGetEmpCheckIn.emp_code;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Demo_HHT_EARTH.EMcheckInGroup EG = new EMcheckInGroup("");
            EG.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            GetGroup();
           
            InsertEmGoshow();
            
          
            Demo_HHT_EARTH.EMcheckInGroup EG = new EMcheckInGroup(s);
            EG.Show();
        }

        private void GetGroup()
        {
            try
            {
                group = selectGroup.SelectedItem.ToString();
            }
            catch (Exception)
            {

                group = "Unknown";
            }
           
        }
        string s = string.Empty;
        private void InsertEmGoshow()
        {
            try
            {
                cn2.ConnectionString = "Data Source=|DataDirectory|db.sqlite";
            }
            catch (Exception)
            {

                MessageBox.Show("notconect SQLite");
            }
            string datenow = String.Format("{0:M/d/yyyy}", DateTime.Now);
            Guid flig_em_id = Guid.NewGuid();
            strconinsert = "INSERT INTO [t_earth_flight_employee] (earth_flight_employee_id,flight_id,flight_employee_id,employee_code,employee_group,status,check_in_flag,check_in_datetime,employee_display_name,create_date,create_by) VALUES('"
                        + flig_em_id.ToString()
                        + "','" + Demo_HHT_EARTH.DataGetflightInfo.Gufld_id
                        + "','" + ""
                        + "','" + Demo_HHT_EARTH.DataGetEmpCheckIn.emp_code
                        + "','" + group
                        + "','" + "GOSHOW"
                        + "','" + "YES"
                        + "','" + datenow
                        + "','" + ""
                        + "','" + datenow
                        + "','" + Demo_HHT_EARTH.GobalVariableEARTH.UserID
                        + "')";


            SQLiteCommand command = new SQLiteCommand(strconinsert, cn2);
            cn2.Open();
            command.Connection = cn2;

            command.ExecuteNonQuery();
            cn2.Close();
            s = string.Empty;
             s = "success";
        }

        private void FindGroupEm()
        {

            try
            {
                cn2.ConnectionString = "Data Source=|DataDirectory|db.sqlite";
            }
            catch (Exception)
            {
                //label3.Visible = true;
               // label3.Text = "no data";

               
            }
            string strcomm = "SELECT employee_group from v_earth_dropdown_employee_group where employee_group !='Unknown' ";
            SQLiteCommand COMM = new SQLiteCommand(strcomm, cn2);
            SQLiteDataAdapter Ldas = new SQLiteDataAdapter(COMM);
            droplist = new DataSet();
            cn2.Open();
            cn2.Close();
            Ldas.Fill(droplist, "L_emp");

            selectGroup.DisplayMember = "employee_group";
            selectGroup.ValueMember = "employee_group";
           // selectGroup.DataSource = droplist.Tables[0];
           /// while (droplist.Tables[0].Rows.Count > 0)
            //{
            //selectGroup.Items.Add(droplist);
           // }
            //selectGroup.Items.Add
            if (droplist.Tables[0].Rows.Count > 0)
            {
                selectGroup.Items.Add("Unknown");
                for (int i = 0; i < droplist.Tables[0].Rows.Count; i++)
                {
                    selectGroup.Items.Add(droplist.Tables[0].Rows[i]["employee_group"].ToString());
                }
                
            }

        }

        private void EMCheckInConfirm_Click(object sender, EventArgs e)
        {

        }

        
    }
}
